<?php

namespace App\Http\Requests\Client\Work;

use App\Exceptions\GeneralException;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;

class WorkCreate extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     * @throws GeneralException
     */
    public function authorize()
    {
        $user = Auth::guard('courier')->user();
        // 判断是有权限入库  0入库  1派件  2所有权限
        if ($user->jurisdiction == 0 || $user->jurisdiction == 2) {
            return true;
        } else {
            throw new GeneralException('您没入库权限', 403);
        }
    }

    /**
     * 定义表单规则
     *
     * Date: 2018/05/25
     * @author Tenny
     * @return array
     */
    public function rules()
    {
        return [
            'single_number' => 'required|string',
            'to_mobile' => 'required|string',
            'take_code' => 'required|min:6|max:6',
        ];
    }

    /**
     * 定义错误响应消息
     *
     * Date: 2018/05/25
     * @author Tenny
     * @return array
     */
    public function messages()
    {
        return [
            'single_number.integer' => '请上传快递号',
            'single_number.string' => '请上传正确的快递号',
            'to_mobile.required' => '请上传收件人电话',
            'to_mobile.string' => '请上传正确的电话号码',
            'take_code.required' => '请上传取件码',
            'take_code.min' => '密码不得少于:min个字符',
            'take_code.max' => '密码不得少于:max个字符',
        ];
    }
}
